package com.qiye.pointsserver.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CorsConfig {

    @Bean
    public WebMvcConfigurer corsConfigurer() {
        return new WebMvcConfigurer() {
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping("/**")               // 允许所有路径跨域
                        .allowedOrigins("*")             // 允许所有域名访问，生产环境可换成具体域名
                        .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")  // 允许的方法
                        .maxAge(3600);                   // 预检请求缓存时间（秒）
            }
        };
    }
}
